package com.wang.springframework.test.common;

import com.wang.springframework.beans.BeansException;
import com.wang.springframework.beans.factory.config.BeanPostProcessor;
import com.wang.springframework.test.bean.UserService;

/**
 * @author wangjianhua
 * @Description
 * @date 2021/8/25/025 17:20
 **/
public class MyBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessorBeforeInitialization(Object bean, String beanName) throws BeansException {
        if("userService".equals(beanName)){
            UserService userService = (UserService) bean;
            userService.setLocation("通过BeanPostProcessor的postProcessorBeforeInitialization方法修改的location");
        }
        return bean;
    }

    @Override
    public Object postProcessorAfterInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }
}
